package appapi.service.impl;

import appapi.Request.Basic.OperItemReq;
import appapi.Vo.OperItemTreeVo;
import appapi.dao.OperatingItemMapper;
import appapi.dao.OperatingtypeMapper;
import appapi.entity.basic.OperatingItemEntity;
import appapi.entity.basic.OperatingTypeEntity;
import appapi.service.OperatingItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 作业项目业务
 *
 * @author luocheng
 * @version 1.0
 * @date 2023/05/26 10:19
 */
@Service
public class OperatingItemServiceImpl extends ServiceImpl<OperatingItemMapper, OperatingItemEntity> implements OperatingItemService {

    @Resource
    OperatingtypeMapper operatingTypeMapper;
    @Autowired
    private OperatingItemMapper operatingItemMapper;

    @Override
    public List<OperatingItemEntity> getList(OperItemReq req) {
        return operatingItemMapper.selectList(req);
    }

    @Override
    public OperatingItemEntity getDetail(Long operItemId) {
        return operatingItemMapper.selectById(operItemId);
    }

    @Override
    public List<OperatingTypeEntity> getTree() {
        //查到所有类型
        List<OperatingTypeEntity> operatingTypeEntities = operatingTypeMapper.selectList((String) null);

        return  operatingTypeEntities.stream().map(map->{
            //OperItemTreeVo vo = new OperItemTreeVo();
            OperItemReq operItemReq = new OperItemReq();

            operItemReq.setOperTypeId(map.getOperTypeId());
            map.setChild(getList(operItemReq));
            return map;
        }).collect(Collectors.toList());
    }
}
